#include <iostream>
using namespace std;
int main()
{
  int ans = 0;
  for(int i = 1;i <= 2025;i++){
    if(i %3 == 0 || i %8 == 0 ||i %38 == 0){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string str;
  cin>>str;
  int cnt1 = 0,cnt2 = 0;
  for(char c :str){
    if(c == 'a'){
      cnt1++;
    }else{
      cnt2 = max(cnt1,cnt2);
      cnt1 = 0;
    }
  }
   cnt2 = max(cnt1,cnt2);
  string ans (cnt2 + 1,'a');
  cout << ans << endl;
  return 0;
}
#include <iostream>
#include <string>
#include <queue>
using namespace std;
int num[50050];
int main()
{
  int n;  cin>>n;
  string str; cin>>str;
  int cnt = 50000;
  bool t = false;
  for(int i = 1;i <=n;i++){
    if(str[i - 1] == '1')
    {
      t = true;
      cnt = 0;
    }else{
      cnt++;
    }
    num[i] = cnt;
  }
  if(t == false){
    // cout << -1 <<endl;
  for(int i = 1;i<=n;i++){
    if(str[i - 1] == '0'){
      cout << -1 <<' ';
    }
  }
    return 0;
  }
  cnt = 50000;
  for(int i = n;i >= 1;i--){
    if(str[i - 1] == '1'){
      cnt = 0;
    }else{
      cnt++;
    }
    num[i] = min(cnt,num[i]);
  }
  for(int i = 1;i<=n;i++){
    if(str[i - 1] == '0'){
      cout << num[i] <<' ';
    }
  }
  return 0;
}
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int num[100005];
// 1  
// 2   1
// 3   2
// 4   3
// 5   
using ll = long long;
ll fun(ll pos, ll k) {
    if (k == 1) return 0;
    if (k == 2) return num[pos] - num[pos - 1];
    ll ans = 0;
    for (int i = 0; i < k; i++) {
    ans += (ll)num[pos - i] * (k - i - 1 - i);
     }
    return ans;
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, k;  cin >> n >> k;
	for (int i = 1; i <= n; i++)  cin >> num[i];
	if (k == 1) {
		cout << 0 << endl;
		return 0;
	}
	sort(num + 1, num + 1 + n);
	ll ans = fun(k, k);
	ll tmp = ans;
	ll sum = 0;
	for (int i = 1; i <= k; i++) {
		sum += num[i];
	}





	for (int i = k + 1; i <= n; i++) {
		sum -= num[i - k];
		tmp -= sum - (ll)num[i - k] * (k - 1);
		tmp += (ll)num[i] * (k - 1) - sum;
		sum += num[i];
		ans = min(ans, tmp);
		// cout << tmp << endl;
	}
	cout << ans;
	return 0;
}